package com.beetobe.callib;

import android.annotation.SuppressLint;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;

import com.beetobe.callib.calendar.AsyncDeleteCalendar;
import com.beetobe.callib.calendar.AsyncUpdateCalendar;
import com.beetobe.main.MainActivity;
import com.beetobe.main.schedule.CalendarActivity;
import com.beetobe.main.schedule.TimeScheduleActivity;
import com.google.api.services.calendar.model.Calendar;

@SuppressLint({ "ParserError", "ParserError" })
public class CalendarDialogBuilder {
	
	private MainActivity CalendarListActivity;
	private LayoutInflater layoutInflater;
	private View promptsView;
	
	public CalendarDialogBuilder(final MainActivity CalendarListActivity) {
		this.layoutInflater = LayoutInflater.from(CalendarListActivity);
		this.CalendarListActivity = CalendarListActivity;
	}
	
	public void getCalendarInsertDiglog(int layout, int editTextId, int btnMonthId, int btnClockId) {
		this.promptsView = layoutInflater.inflate(layout, null);

		final AlertDialog.Builder alertDlg = new AlertDialog.Builder(CalendarListActivity);
		alertDlg.setView(promptsView);

		final EditText userInput = (EditText) promptsView.findViewById(editTextId);
		final Button btnMonth = (Button) promptsView.findViewById(btnMonthId);
		final Button btnClock = (Button) promptsView.findViewById(btnClockId);
		
		CalendarLibHelper.newCalendarName = userInput.getText().toString();
		
		final AlertDialog tmpDlg = alertDlg.setTitle("Create Bee")
		.setCancelable(false)
		.setMessage("모임을 생성합니다.")
//				.setPositiveButton("OK", new DialogInterface.OnClickListener() {
//					public void onClick(DialogInterface dialog,	int whichButton) {
//						Calendar entry = new Calendar();
//						entry.setSummary(userInput.getText().toString());
//						new AsyncInsertCalendar(CalendarListActivity, entry).execute();
//					}
//				})
		.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
			public void onClick(DialogInterface dialog,	int which) {
				dialog.cancel();
			}
		})
		.show();
		
		btnMonth.setOnClickListener(new Button.OnClickListener() {
			public void onClick(View v) {
				CalendarLibHelper.newCalendarName = "[BeeToBe] " + userInput.getText().toString();
				tmpDlg.dismiss();
				
				Intent intent = new Intent(CalendarListActivity, CalendarActivity.class);
				intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
				CalendarListActivity.startActivity(intent);
			}
		});
		
//		btnClock.setOnClickListener(new Button.OnClickListener() {
//			public void onClick(View v) {
//				CalendarLibHelper.newCalendarName = "[BeeToBe] " + userInput.getText().toString();
//				tmpDlg.dismiss();
//				
//				Intent intent = new Intent(CalendarListActivity, TimeScheduleActivity.class);
//				intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
//				CalendarListActivity.startActivity(intent);
//				
//			}
//		});
	}
	public  void getCalendarDeleteDialog(int layout, final int calendarIndex){
		View promptsView = layoutInflater.inflate(layout, null);

		AlertDialog.Builder alertDlg = new AlertDialog.Builder(CalendarListActivity);
		alertDlg.setView(promptsView);
		
		alertDlg.setTitle("Delete Bee")
				.setCancelable(false)
				.setMessage("모임을 삭제하시겠습니까?")
				.setPositiveButton("OK", new DialogInterface.OnClickListener() {
					public void onClick(DialogInterface dialog,	int whichButton) {
						new AsyncDeleteCalendar(CalendarListActivity, calendarIndex).execute();
					}
				})
				.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
					public void onClick(DialogInterface dialog,	int which) {
						dialog.cancel();
					}
				})
				.show();
	}
//	public  void getCalendarUpdateDialog(int layout, int editTextId, final int calendarIndex){
//		View promptsView = layoutInflater.inflate(layout, null);
//
//		AlertDialog.Builder alertDlg = new AlertDialog.Builder(CalendarListActivity);
//		alertDlg.setView(promptsView);
//		
//		final EditText userInput = (EditText) promptsView.findViewById(editTextId);
//		
//		alertDlg.setTitle("Edit Calendar")
//				.setCancelable(false)
//				.setMessage("���ο� Ķ���� �̸��� ����ּ���")
//				.setPositiveButton("OK", new DialogInterface.OnClickListener() {
//					public void onClick(DialogInterface dialog,	int whichButton) {
//						Calendar entry = new Calendar();
//						entry.setSummary(userInput.getText().toString());
//						new AsyncUpdateCalendar(CalendarListActivity, calendarIndex, entry).execute();
//					}
//				})
//				.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
//					public void onClick(DialogInterface dialog,	int which) {
//						dialog.cancel();
//					}
//				})
//				.show();
//	}
}

